package com.scy.java.io.output;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

//文件输出流的创建方式
public class FileWriterTest {
    public static void main(String[] args) {
        //方式一：给定要读取的file对象，创建FileWriter对向
        FileWriter fileWriter =null;
        FileWriter fileWriter1 =null;

        try {
            File file = new File("fw.txt");
            fileWriter = new FileWriter(file);
            //方式二：给定要读取的文件名称
            fileWriter1 = new FileWriter("fw1.txt");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            //关闭流
            if (fileWriter1 != null) {
                try {
                    fileWriter1.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (fileWriter != null) {
                try {
                    fileWriter.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

    }

}
